# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=scons
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.0.1
pkgrel=2
pkgdesc="Extensible Python-based build utility (mingw-w64)"
arch=('any')
license=('MIT')
url="https://scons.org"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/${_realname}/${_realname}/archive/${pkgver}.tar.gz"
        "001-no-pywin32.patch")
sha256sums=('eca75e5b6d0b3df23370da095a8851d781e2522e9e9d2764ae2878f3e34c58da'
            'd7b7053d3891867b19e31cca9c34211d86f8cf5b3c876905ed46ba62275e2c56')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # "There should be no other dependencies or requirements to run SCons,
  # although the pywin32 Python package is strongly recommended if running on Windows systems."
  patch -Np1 -i "${srcdir}"/001-no-pywin32.patch
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1

  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/scons-configure-cache-script.py"
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/scons-script.py"
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/sconsign-script.py"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
